<template>
  <div class="CustomWrapInput">
    <div class="title">{{title}}</div>
    <div v-if="desc" class="desc">{{desc}}</div>
    <div v-if="isInput" class="input">
      <i-input
        :type="inputType"
        :value="cloneValue === 0 || cloneValue ? cloneValue : ''"
        :placeholder="placeholder"
        @change="inputChange" />
    </div>
    <div
      v-if="!isInput"
      class="noInput"
      :class="{isContent: cloneValue !== '' && cloneValue !== null}"
      @tap="inputClick">
      {{cloneValue === '' || cloneValue === null ? placeholder : cloneValue}}
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    desc: {
      type: String,
      default: ''
    },
    inputType: {
      type: String,
      default: 'text'
    },
    isInput: {
      type: Boolean,
      default: true
    },
    value: {
      type: String,
      default: ''
    },
    placeholder: {
      type: String,
      default: ''
    }
  },
  watch: {
    value (newValue) {
      if (!this.isInput) {
        this.initValue()
      }
    }
  },
  mounted () {
    this.initValue()
  },
  data () {
    return {
      cloneValue: ''
    }
  },
  methods: {
    inputClick () {
      if (this.isInput) {
        return
      }

      this.$emit('inputClick', this.title)
    },
    inputChange (e) {
      this.cloneValue = e.target.detail.value
      this.$emit('input', this.cloneValue)
    },
    initValue () {
      this.cloneValue = this.value
    },
    getValue () {
      return this.cloneValue
    }
  }
}
</script>

<style lang="scss" scoped>
  .CustomWrapInput {
    padding-top: 10px;
    background-color: white;
    font-size: 15px;
    color: #495060;
    > .title,
    > .desc {
      padding: 0 15px;
    }
    > .title {
      margin-bottom: 8px;
    }
    > .desc {
      font-size: 12px;
      color: rgb(163, 163, 163);
    }
    > .noInput {
      height: 40px;
      padding: 0 15px;
      color: rgb(219, 219, 219);
      display: flex;
      align-items: center;
      font-size: 14px;
      &.isContent {
        color: #495060;
      }
    }
  }
</style>
